var eap_sa_user = {
	init : function(tabId) {
		var $userId = $('[name="model.loginUser.id"]', getActiveDom());
		if ($userId.length == 0) {
			$userId = $('[name="model.id"]', getActiveDom());
		}
		var templateId = $userId.val();
		var $privilegeCtn = $('#privilegeCtn');
		$privilegeCtn.load(g_base_site + '/espirit/eap/sa/privilege.show.html?tabId=' + tabId + '&templateId=' + templateId, function() {
			$('#privilegeCtn').removeClass('loading');
		});
		var $form = $privilegeCtn.closest('.jform');
		initValidate($form);
		
		$('[cmbname="model.defaultWebsite.id"]', getActiveDom()).on('select', function(event, ui) {
			var websiteId = Ognl.get(ui.item, 'id');
			$privilegeCtn.load(g_base_site + '/espirit/eap/sa/privilege.show.html?tabId=' + tabId + '&templateId=' + templateId + '&websiteId=' + websiteId, function() {
				$('#privilegeCtn').removeClass('loading');
			});
		});
	},
	
	saveUserPrivilege: function (btn) {
		var $btn = $(btn);
		if ($btn.hasClass("disabled")) {
			return;
		}
		$btn.addClass("disabled");
		
		var $form = $btn.closest('.jform');
		var ret = ajaxSubmit($form, {
			data: {_resultCode:'$json'},
			success:function(data) {
				var $data = $(data);
				if ($data.hasClass('error')) {
					showError($data.html());
				} else {
					closeTabPage(null, true);
				}
			}
		});
		if (!ret) {
			$btn.removeClass("disabled");
		}
	}
}